package com.qf.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author Zwnan
 */
@RestController
@RequestMapping("search")
public class SearchController {
    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private SearchService searchService;

    @PostMapping("/searchcount")
    public Long searchCount(@RequestParam("count") String count) throws Exception {

        Map counts = objectMapper.readValue(count, Map.class);

        Long c = searchService.searchCount(counts);

        return c;

    }
    @PostMapping("/search")
    public List<Map> searchLog(@RequestParam("count") String count) throws Exception {
        Map counts = objectMapper.readValue(count, Map.class);
        List<Map> data = searchService.searchLogs(counts);
        return data;
    }
    @PostMapping("/statStatus")
    public Map<String, Long> statSendStatus(@RequestParam("params") String params) throws Exception {
        //1. 将params手动的反序列化为Map对象
        Map parameter = objectMapper.readValue(params, Map.class);

        //2. 调用service查询数据总条数
        Map<String, Long> data = searchService.statSendStatus(parameter);

        //3. 返回
        return data;
    }


}
